#if !defined(_UTILITY_H)
#define _UTILITY_H

#include <boost/regex.hpp>

#include "alias.h"
#include "SArgumentException.h"

CREATE_ALIAS( SNumber )
CREATE_ALIAS( SByte )
CREATE_ALIAS( SValue )
CREATE_MAP_ALIAS( SValue )
CREATE_ALIAS( SStruct )
CREATE_MAP_ALIAS( SStruct )
CREATE_ALIAS( TypeDescriptor )

/**
 * Class that store a set of useful static functions
 */ 
class DECLARATION_DLL Utility
{

public:

	/**
	 * Returns true if type is a complex type
	 */
	static bool IsComplexType(SType type);

	/**
	 * Returns true if type is a simple type
	 */
	static bool IsSimpleType(SType type);

	/**
	 * Returns true if name is a valid variable name
	 */
	static bool IsValidName(string name);

	/**
 	 * Returns the fully qualified name
 	 */
	static string GetFullyQualifiedName(string pluginName, string name);

	/**
	 * Convert a number from hexadecimal to decimal
	 * Example: "A2" -> "162"  ( no prefix )
	 */
	static long HexToDec(string s);


	/**
	 * Check if the character c is printable.
	 */
	static bool IsPrintable(char c);
	
	/**
	 * Get the type name from a type
	 */
	static string GetTypeName(SType type);

	/**
	 * Get the type from the type name
	 */
	static SType GetTypeFromName(string type);

	/**
	 * Create a simple type variable instance parsing a string value representation.
	 */ 
	static SValueSp SimpleParse(SType type, string s);

	/**
	 * Create a complex type variable instance parsing a string value representation.
	 */ 
	static SValueSp ComplexParse(TypeDescriptorSp typeDescriptor, string s, SValueSpMapSp vars);

	/** 
	 * This function is used in the struct and vector parser.
	 * Get arguments ignoring commas inside a nested brackets.
	 * So after the split a merging operation is needed.
	 *
	 * Example: num=10, color=red, ss=[str=\"Hi\", num=0xFFFF]
	 *   arg[0]: num=10
	 *   arg[1]: color=red
	 *   arg[2]: ss=[str=\"Hi\"
	 *   arg[3]: num=0xFFFF]
	 *
	 * arg[2] and arg[3] will be merged !
	 */
	static void MergeArgs( string stringArgs, StringVector& args );

	/**
	 * Replaces each format item in the format string with the text equivalent
	 * of a corresponding expression's value and return all in a string.
	 * The variable list is specified with a vector of SValue.
	 */
	static string Format( string format, SValueSpVectorSp listVars, SValueSpMapSp vars);
	static string Format( string format, SValueSpVectorSp listVars, SStructSp str);

	/**
	 * Replaces each format item in the format string with the text equivalent
	 * of a corresponding expression's value and return all in a string.
	 * The variable list is specified with a string.
	 */
	static string Format( string format, string listVarsString, SValueSpMapSp vars);
	static string Format( string format, string listVarsString, SStructSp str);

	/**
	 * Create a 16 bit SNumber from two SByte value. 
	 */
	static SNumberSp BuildNumber(SByteSp b1, SByteSp b2);

	/**
	* Create two SByte from nibbles of a byte. 
	*/
	static void SplitNumber(SByteSp b, SByteSp& b1, SByteSp& b2);

	/**
	 * Get in a string a representation of a variable in a pretty way.
	 */
	static string GetPrettyPrintVar( SValueSp var );
};

#endif
